<template>
  <el-dialog
    :title="title"
    :visible.sync="open"
    width="70%"
    :before-close="handleClose"
    class="dialogClass"
  >
    <el-form ref="ruleForm" :model="ruleForm" label-width="80px">
      <el-row :gutter="20">
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="日期:"
            prop="riqi"
            label-width="150px"
          >
            <el-input
              size="big"
              v-model="ruleForm.riqi"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="利润:"
            prop="lirun"
            label-width="150px"
          >
            <el-input
              size="big"
              v-model="ruleForm.lirun"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="犊牛饲料价格:"
            prop="siliaoduniu"
            label-width="150px"
          >
            <el-input
              size="big"
              v-model="ruleForm.siliaoduniu"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item label="育成牛饲料价格:" prop="siliaoyucheng" label-width="150px">
            <el-input size="big" v-model="ruleForm.siliaoyucheng" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="青年牛饲料价格"
            prop="siiaoqingnian"
            label-width="150px"
          >
            <el-input
              size="big"
              v-model="ruleForm.siiaoqingnian"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="泌乳牛饲料价格"
            prop="siliaomiru"
            label-width="150px"
          >
            <el-input size="big" v-model="ruleForm.siliaomiru" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="干奶牛饲料价格"
            prop="siliaogannai"
            label-width="150px"
          >
            <el-input
              size="big"
              v-model="ruleForm.siliaogannai"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="犊牛药品价格"
            prop="yaopinduniu"
            label-width="150px"
          >
            <el-input size="big" v-model="ruleForm.yaopinduniu" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="育成牛药品价格"
            prop="yaopinyucheng"
            label-width="150px"
          >
            <el-input
              size="big"
              v-model="ruleForm.yaopinyucheng"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item label="青年牛药品价格" prop="yaopinqingnian" label-width="150px">
            <el-input size="big" v-model="ruleForm.yaopinqingnian" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="成母牛药品价格"
            prop="yaopinchengmu"
            label-width="150px"
          >
            <el-input
              size="big"
              v-model="ruleForm.yaopinchengmu"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="犊牛精液价格"
            prop="jingyeduniu"
            label-width="150px"
          >
            <el-input size="big" v-model="ruleForm.jingyeduniu" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="育成牛精液价格"
            prop="jingyeyucheng"
            label-width="150px"
          >
            <el-input
              size="big"
              v-model="ruleForm.jingyeyucheng"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="青年牛精液价格"
            prop="jingyeqingnian"
            label-width="150px"
          >
            <el-input size="big" v-model="ruleForm.jingyeqingnian" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="成母牛精液价格"
            prop="jingyechengmu"
            label-width="150px"
          >
            <el-input size="big" v-model="ruleForm.jingyechengmu" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="牛奶价格"
            prop="xiaoshouniunai"
            label-width="150px"
          >
            <el-input size="big" v-model="ruleForm.xiaoshouniunai" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="公犊牛价格"
            prop="xiaoshougongdu"
            label-width="150px"
          >
            <el-input size="big" v-model="ruleForm.xiaoshougongdu" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="母犊牛价格"
            prop="xiaoshoumudu"
            label-width="150px"
          >
            <el-input size="big" v-model="ruleForm.xiaoshoumudu" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="育成牛价格"
            prop="xiaoshouyucheng"
            label-width="150px"
          >
            <el-input size="big" v-model="ruleForm.xiaoshouyucheng" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="青年牛价格"
            prop="xiaoshouqingnian"
            label-width="150px"
          >
            <el-input size="big" v-model="ruleForm.xiaoshouqingnian" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="8" :lg="8">
          <el-form-item
            label="成母牛价格"
            prop="xiaoshouchengmu"
            label-width="150px"
          >
            <el-input size="big" v-model="ruleForm.xiaoshouchengmu" clearable></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button
        type="primary"
        size="big"
        @click="onSubmit('ruleForm')"
        :loading="loading"
        >{{ submitButton }}</el-button
      >
      <el-button size="big" @click="resetForm('ruleForm')">重置</el-button>
      <el-button size="big" @click="close('ruleForm')">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { updatefarmprofitanalysis,savefarmprofitanalysis} from '@/apis/employee/FarmProfitAnalysis'

export default {
  data() {
    return {
      // 提交按钮
      submitButton: "",
      // 控制弹窗
      open: false,
      // 控制按钮加载状态
      loading: false,
      // 弹窗标题
      title: "",
      // 表单项
      ruleForm: {
        xiaoshouqingnian: "",
        xiaoshouyucheng: "",
        jingyeyucheng: "",
        xiaoshoumudu: "",
        xiaoshougongdu: "",
        yaopinduniu: "",
        yaopinchengmu: "",
        lirun: "",
        xiaoshouchengmu: "",
        jingyeduniu: "",
        siliaomiru: "",
        xiaoshouniunai: "",
        jingyeqingnian: "",
        siiaoqingnian: "",
        yaopinyucheng: "",
        siliaogannai: "",
        riqi: "",
        yaopinqingnian: "",
        siliaoduniu: "",
        siliaoyucheng: "",
        jingyechengmu: "",
      },
    };
  },
  methods: {
    // 控制弹窗
    show(title, row) {
      const _this = this;
      _this.title = title;
      _this.open = true;
      if (row) {
        _this.submitButton = "修改";
        _this.ruleForm = JSON.parse(JSON.stringify(row));
      } else {
        _this.submitButton = "确定登记";
      }
    },
    close(formName) {
      this.open = false;
      this.resetForm(formName);
    },
    handleClose(done) {
      const _this = this;
      _this
        .$confirm("系统可能不会保存您的更改", "确认关闭？")
        .then((_) => {
          done();
          _this.resetForm("ruleForm");
        })
        .catch((_) => {});
    },
    onSubmit(formName) {
      const _this = this;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (_this.title == "创建牛场利润") {
            // console.log(_this.ruleForm);
            savefarmprofitanalysis(_this.ruleForm).then(function (res) {
              // console.log("res: ", res.code);
              if (res.code === 0) {
                _this.$alert(res.msg, "提示", {
                  confirmButtonText: "确定",
                  callback: (action) => {
                    _this.close("ruleForm");
                    _this.$parent.$parent.search();
                  },
                });
              }
            });
          } else {
            updatefarmprofitanalysis(_this.ruleForm).then(function (res) {
              // console.log("res: ", res.code);
              if (res.code === 0) {
                _this.$alert(res.msg, "提示", {
                  confirmButtonText: "确定",
                  callback: (action) => {
                    _this.close("ruleForm");
                    _this.$parent.$parent.search();
                  },
                });
              }
            });
          }
        }
      });
    },
    // 表单重置
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style scoped>
</style>